<template>
  <div>
    <div style="margin: 40px" class="box">
      <el-card class="box-card" shadow="hover">
        <p>产品添加</p>
        <span class="xx" @click="close()">X</span>
        <div class="form">
          <label for="">手机名称</label>
          <span>*</span>
          <!-- <input class="s1" type="text" v-model="form.name" /> -->
          <el-input class="s1" v-model="form.name" placeholder="请输入手机名称"></el-input>

          <label for="">手机价格</label>
          <span>*</span>
          <!-- <input class="s1" type="text" v-model="form.price" /> -->
          <el-input class="s1" v-model="form.price" placeholder="请输入手机价格"></el-input>
          <label for="">手机尺寸</label>
          <span>*</span>
          <!-- <input class="s1" type="text" v-model="form.phone_size" /> -->
          <el-select
            class="s1"
            v-model="form.phone_size"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in cc"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>

          <label for="">运行内存</label>
          <span>*</span>
          <!-- <input class="s1" type="text" v-model="form.electric" /> -->
          <el-select
            class="s1"
            v-model="form.electric"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in yunx"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>

          <label for="">手机内存</label>
          <span>*</span>
          <!-- <input class="s1" type="text" v-model="form.thickness" /> -->
          <el-select
            class="s1"
            v-model="form.thickness"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in sjnz"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>

          <label for="">手机品牌</label>
          <span>*</span>

          <el-select
            class="s1"
            v-model="form.pingpai"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>

          <label for="">手机类别</label>
          <span>*</span>
          <!-- <input class="s2" type="text" v-model="form.phone_type" /> -->
          <el-select v-model="form.phone_type" clearable placeholder="请选择">
            <el-option
              v-for="item in leibie"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>

          <div class="tj">
            <label for="">推荐指数</label>
            <span>*</span>
            <el-rate v-model="form.star"></el-rate>
          </div>

           
          <div class="tex">
            <label for="">详情</label>
            <span>*</span>
            <!-- <input class="s2" type="textarea"  autosize v-model="form.yingxiang" /> -->
            <div class="edit_container">
              <quill-editor
                v-model="form.parameter"
                ref="myQuillEditor"
                class="editer"
                @ready="onEditorReady($event)"
              >
              </quill-editor>
            </div>
          </div>
          <div class="uplod">
            <label for="">图片上传</label>
            <span>*</span>
            <el-upload
              class="upload-demo"
              action="http://192.168.3.180:7001/api/uploadPicture"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              list-type="picture"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </div>
          <div class="uplod">
            <label for="">多张图片上传</label>
            <span>*</span>
            <el-upload
              class="upload-demo"
              action="http://192.168.3.180:7001/api/uploadPicture"
              :on-preview="Preview"
              :on-remove="Remove"
              list-type="picture"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </div>
        </div>
        <div>
          <el-button @click="readit()">重 置</el-button>
          <el-button @click="close()">取 消</el-button>
          <el-button type="primary" @click="submit()">提 交</el-button>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { postProduce } from "@/api/table";
import { quillEditor } from "vue-quill-editor"; //调用编辑器
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
export default {
  propt: [],
  components: {
    quillEditor,
  },
  data() {
    return {
      options: [
        {
          value: "华为",
          label: "华为",
        },
        {
          value: "小米",
          label: "小米",
        },
        {
          value: "OPPO",
          label: "OPPO",
        },
        {
          value: "vivo",
          label: "vivo",
        },
        {
          value: "黑鲨",
          label: "黑鲨",
        },
        {
          value: "iPhone",
          label: "iPhone",
        },
        {
          value: "三星",
          label: "三星",
        },
      ],
      leibie: [
        {
          value: "5G手机",
          label: "5G手机",
        },
        {
          value: "拍照手机",
          label: "拍照手机",
        },
        {
          value: "游戏手机",
          label: "游戏手机",
        },
        {
          value: "折叠手机",
          label: "折叠手机",
        },
        {
          value: "续航手机",
          label: "续航手机",
        },
      ],
      sjnz: [
        {
          value: "32GB",
          label: "32GB",
        },
        {
          value: "64GB",
          label: "64GB",
        },
        {
          value: "128GB",
          label: "128GB",
        },
        {
          value: "256GB",
          label: "256GB",
        },
        {
          value: "512GB",
          label: "512GB",
        },
        {
          value: "1T",
          label: "1T",
        },
      ],
      yunx: [
        {
          value: "4GB",
          label: "4GB",
        },
        {
          value: "6GB",
          label: "6GB",
        },
        {
          value: "8GB",
          label: "8GB",
        },
        {
          value: "12GB",
          label: "12GB",
        },
        {
          value: "32GB",
          label: "32GB",
        },
      ],
      cc: [
        {
          value: "6.8寸",
          label: "6.8寸",
        },
        {
          value: "6.7寸",
          label: "6.7寸",
        },
        {
          value: "6.1寸",
          label: "6.1寸",
        },

        {
          value: "6.5寸",
          label: "6.5寸",
        },
        {
          value: "6.4寸",
          label: "6.4寸",
        },
        {
          value: "5.4寸",
          label: "5.4寸",
        },
        {
          value: "4.7寸",
          label: "5.7寸",
        },
      ],
      value: "",
      value1: null,

      colors: ["#99A9BF", "#F7BA2A", "#FF9900"], // 等同于 { 2: '#99A9BF', 4: { value: '#F7BA2A', excluded: true }, 5: '#FF9900' }

      labelPosition: "right",
      formLabelWidth: "100px",
      adminList: [],
      a: [],
      imageUrl: "",
      imageName: "http://192.168.3.190:7001/",
      form: {
        id: null,
        name: "",
        phone_type: "",
        phone_size: "",
        electric: "",
        thickness: "",
        picture: "",
        pictures: "",
        price: "",
        pingpai: "",
        parameter: "",
        star: "",
      },
    };
  },
  created() {
    this.$route.query;
    console.log(this.$route.query);
    this.form = this.$route.query;
  },
  computed: {
    editor() {
      return this.$refs.myQuillEditor.quill;
    },
  },
  methods: {
    onEditorReady(editor) {},
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file.response.data);
      this.form.picture = file.response.data;
    },
      Remove(file, fileList) {
      console.log(file, fileList);
    },
    Preview(file) {
      console.log(file);
      this.a.push(file.response.data);
      console.log(file.response.data);
      this.form.pictures = this.a;
    },
    submit() {
      let params = {};
      params = { ...this.form };
      console.log(params);
      postProduce(params).then((res) => {
        console.log(res);
        if (res.code === 0) {
          this.$message({
            message: "添加产品成功",
            type: "success",
          });
        } else {
          this.$message.error("添加产品失败");
        }
        this.$router.push({ path: "/product/index" });
      });
    },
    // 重置
    readit() {
      this.form.id = "";
      this.form.name = "";
      this.form.phone_type = "";
      this.form.phone_size = "";
      this.form.electric = "";
      this.form.thickness = "";
      this.form.picture = "";
      this.form.pictures = "";
      this.form.price = "";
      this.form.pingpai = "";
      this.form.parameter = "";
      this.form.star = "";
    },
    close() {
      this.$router.push({ path: "/product/index" });
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
 width: 1480px;
  height: 600px;
  p {
    width: 50px;
    font-size: 18px;
    font-weight: bold;
    display: inline;
  }
  .xx {
    width: 30px;
    height: 30px;
    margin-left: 1354px;
    cursor: pointer;
    font-size: 18px;
  }
  .box-card {
    font-size: 14px;
    .form {
      span {
        color: red;
        margin: 0 10px;
      }
      .s1 {
        width: 375px;
        height: 30px;
        text-indent: 10px;
        margin: 20px 20px 20px 0;
      }
      .s2 {
        width: 850px;
        height: 30px;
        margin: 20px 20px 20px 0;
      }
      .tj {
        margin: 20px 0;
        .el-rate {
          display: inline;
          width: 200px;
          height: 50px;
        }
      }
      .tex {
        margin: 20px 0;
        .el-textarea {
          width: 860px;
        }
      }

      .uplod {
        margin: 20px 0;
        .upload-demo {
          width: 100px;
          display: inline;
        }
      }
    }
  }
}
img {
  width: 100px;
  height: 100px;
}
.dialog-footer {
  margin: 0 20px;
}
</style> 